package megrez.oss.minio;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;
import megrez.boot.autoconfigure.minio.MinioBucketClient;

/**
 * 初始化桶
 * 
 * @author Lucky Yang
 * @since 2.6.9
 */
@Component
@Slf4j
public class InitBucketDataRunner implements CommandLineRunner {
    @Autowired
    private MinioBucketClient bucketClient;

    @Override
    public void run(String... args) throws Exception {
        createBucket("megrez");
    }

    private void createBucket(String bucketName){
        if (!bucketClient.bucketExists(bucketName)) {
            log.info("Create minio default bucket: {}", bucketName);
            bucketClient.makeBucket(bucketName);
        }

    }
}
